package com.mayikt.service.aop;

import com.google.common.util.concurrent.RateLimiter;
import com.mayikt.service.annotation.MayiktCurrentLimit;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 余胜军
 * @ClassName ExtTransactionalAop
 * @qq 644064779
 * @addres www.mayikt.com
 * 微信:yushengjun644
 */
@Aspect
@Component
public class CurrentLimitAop {
//    @Before(value = "@annotation(com.mayikt.service.annotation.MayiktCurrentLimit)")
//    public void before() {
//        System.out.println("---------------前置通知-----------------");
//    }
//
//    @AfterReturning(value = "@annotation(com.mayikt.service.annotation.MayiktCurrentLimit)")
//    public void afterReturning() {
//        System.out.println("---------------后置通知-----------------");
//    }

    /**
     * 前置
     *
     */

    /**
     * @param joinPoint
     * @return
     * @Around(value = "@annotation(com.mayikt.service.annotation.MayiktCurrentLimit)")
     * 只要方法上有加上该自定义的限流注解 就会被aop环绕通知通知
     */
    @Around(value = "@annotation(com.mayikt.service.annotation.MayiktCurrentLimit)")
    public Object around(ProceedingJoinPoint joinPoint) {
        try {
//            System.out.println("环绕通知开始执行。。。");
//            Object result = joinPoint.proceed();// 执行我们目标方法 public String get() {
//            System.out.println("环绕通知结束执行。。。。");
            /**
             * 目标方法
             */
//            return result;
            return "环绕通知";
        } catch (Throwable throwable) {
            return "系统错误!";
        }

    }

}